<template>
  <div id="app">
    <el-container class="app-container">
      <el-aside width="200px" class="aside-container">
        <el-button class="logout-button" type="primary">退出登录</el-button>
        <el-menu :default-openeds="['1']" class="menu-container">
          <el-submenu index="1">
            <template slot="title">
              <i class="el-icon-menu"></i>
              <span class="menu-title">首页</span>
            </template>
            <el-menu-item index="1-1" class="menu-item">
              <router-link class="rou-link" to="/mainInfo">
                <span class="menu-link-text">首页</span>
              </router-link>
            </el-menu-item>
          </el-submenu>
          <!-- 一级菜单 -->
          <el-submenu v-for="(item, index) in menuList" :key="index" :index="String(index + 2)">
            <!-- 一级菜单名称 -->
            <template slot="title">
              <i class="el-icon-message"></i>
              <span class="menu-title">{{item.menuName}}</span>
            </template>
            <!-- 二级菜单 -->
            <el-menu-item-group v-if="item.subMenuList != null && item.subMenuList != undefined">
              <el-menu-item v-for="(subItem, subIndex) in item.subMenuList" :key="subIndex" :index="(index + 1) + '-' + (subIndex + 1)" class="menu-item">
                <router-link class="rou-link" :to="subItem.url">
                  <span class="menu-link-text">{{subItem.menuName}}</span>
                </router-link>
              </el-menu-item>
            </el-menu-item-group>
          </el-submenu>
        </el-menu>
      </el-aside>

      <!-- 内容 -->
      <el-main class="main-container">
        <router-view/>
      </el-main>
    </el-container>
  </div>
</template>

<script>
import { sendRequest } from "@/util/request";

export default {
  name: "MainInfo",
  data() {
    return {
      menuList: [],
    };
  },
  created() {
    this.getMenuByAccount();
  },
  methods: {
    getMenuByAccount() {
      sendRequest("post", "manager/getMenu")
          .then((res) => {
            console.log(res);
            this.menuList = res.menuList;
          });
    },
  },
};
</script>

<style scoped>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 0;
}

.app-container {
  min-height: 100vh;
  display: flex;
}

.aside-container {


  box-shadow: 0 0 5px rgba(0, 0, 0, 0.2);
}

.logout-button {
  margin: 15px;
  width: 170px;
}

.menu-container {
  padding: 0;
}

.menu-title {
  margin-left: 10px;
  font-size: 16px;
}

.menu-item {
  padding-left: 30px;
  transition: background-color 0.3s ease;
}



.menu-link-text {
  font-size: 18px;
  color: #333333;
}

.main-container {
  flex: 1;
  background-color: #f4f4f4;
  padding: 20px;
}
</style>